﻿/******************************************************************************
 *  作者：       Maxzhang1985
 *  创建时间：   2012/4/28 9:49:20
 *
 *
 ******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using ExtendPropertyLib.WPF;
using ExtendPropertyLib;
using ExORMDesginer.RadWindow.Helper;
using ExORMDesginer.Services;
namespace ExORMDesginer.Plugin.Wizard
{
    public class CodeWizardUIViewModel : ViewModelBase
    {

        public static ExtendProperty ModelProperty = RegisterProperty<CodeWizardUIViewModel>(v => v.Model);
        /// <summary>
        /// 业务实体
        /// </summary>
        public ModelWizard Model { set { SetValue(ModelProperty, value); } get { return (ModelWizard)GetValue(ModelProperty); } }

        public string Result { private set; get; }

        public override string GetViewTitle()
        {
            return "代码生成器设置";
        }


        /// <summary>
        /// 界面载入
        /// </summary>
        public override void OnLoad()
        {
            Model.IsBatch = false;
            Model.LoadInfo();
        }

        /// <summary>
        /// 生成代码
        /// </summary>
        public void Generator()
        {
            if (Model.Model != null)
            {
                if (Model.TemplateInfo.TemplateType == Model.Model.EntityViewType || Model.Model.EntityViewType == EntityType.View)
                {
                    Model.IsBatch = false;
                    this.Result = Model.GetTemplateResult();
                    Model.SaveInfo();
                }
            }
            else
            {
                Model.Host.WindowManager.ShowMessage("没有选择要生成的表对象!");
            }
            this.TryOK();
        }

        /// <summary>
        /// 批量生成
        /// </summary>
        public void AllGenerator()
        {
            Model.IsBatch = true;
            this.Result = Model.GetMoreTemplateResult();
            Model.SaveInfo();
            this.TryOK();
        }

        /// <summary>
        /// 取消
        /// </summary>
        public void Cancel()
        {
            this.TryCancel();
        }



    }
}
